# -*- coding:utf-8 -*-
# @Time:2024/4/1921:01
# @Author:miuzg
# @FileName:new test2.py
# @Software:PyCharm
import time
import requests
from selenium import webdriver
from selenium.webdriver.common.by import By

url = 'https://www.douban.com/'
driver = webdriver.Edge()

driver.get(url)

iframe = driver.find_element(By.XPATH,'//*[@id="anony-reg-new"]/div/div[1]/iframe')

driver.switch_to.frame(iframe)

driver.find_element(By.XPATH,'/html/body/div[1]/div[2]/div[1]/div[3]/div/input').send_keys('18127686385')

driver.find_element(By.XPATH,'/html/body/div[1]/div[2]/div[1]/div[4]/div/div').click()

time.sleep(30)

cookies = driver.get_cookies()

cookie = {}


for data in cookies:
    name = data['name']
    value = data['value']
    cookie[name] = value

print(cookie)

headers = {
    'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0'
}

html = requests.get(url,cookies = cookie,headers = headers).text

with open('豆瓣cookie值.html','w',encoding='utf-8')as f:
    f.write(html)

input()
driver.quit()